package com.icedevcloud.upms.controller.admin.role;

import cn.dev33.satoken.annotation.SaCheckPermission;
import com.icedevcloud.common.core.api.R;
import com.icedevcloud.common.core.log.IceLog;
import com.icedevcloud.common.core.page.PageResult;
import com.icedevcloud.upms.controller.admin.role.dto.AddRoleReqDto;
import com.icedevcloud.upms.controller.admin.role.dto.RolePageReqDto;
import com.icedevcloud.upms.controller.admin.role.dto.SetRoleStatusReqDto;
import com.icedevcloud.upms.controller.admin.role.dto.UpdateRoleReqDto;
import com.icedevcloud.upms.entity.SysRole;
import com.icedevcloud.upms.service.ISysRoleService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import jakarta.validation.constraints.NotNull;
import lombok.RequiredArgsConstructor;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import java.util.List;

/**
 * <p>
 * 角色表 前端控制器
 * </p>
 *
 * @author XiaoBingBy
 * @since 2023-08-13
 */
@Tag(name = "角色接口类")
@RequiredArgsConstructor
@RestController
@RequestMapping("/sysRole")
public class SysRoleController {

    private final ISysRoleService iSysRoleService;

    @IceLog
    @SaCheckPermission("upms:role:page")
    @Operation(summary = "角色列表接口")
    @PostMapping("/rolePage")
    public R<PageResult<SysRole>> rolePage(@RequestBody RolePageReqDto reqDto) {
        PageResult<SysRole> result = iSysRoleService.rolePage(reqDto);
        return R.ok(result);
    }

    @IceLog
    @Operation(summary = "获取所有角色接口")
    @GetMapping("/allRoleList")
    public R<List<SysRole>> allRoleList() {
        List<SysRole> result = iSysRoleService.allRoleList();
        return R.ok(result);
    }

    @IceLog
    @SaCheckPermission("upms:role:add")
    @Operation(summary = "添加角色接口")
    @PostMapping("/add")
    public R<Boolean> add(@RequestBody @Validated AddRoleReqDto reqDto) {
        Boolean result = iSysRoleService.add(reqDto);
        return R.ok(result);
    }

    @IceLog
    @SaCheckPermission("upms:role:setRoleStatus")
    @Operation(summary = "设置角色状态接口")
    @PutMapping("/setRoleStatus")
    public R<Boolean> setRoleStatus(@RequestBody SetRoleStatusReqDto reqDto) {
        Boolean result = iSysRoleService.setRoleStatus(reqDto);
        return R.ok(result);
    }

    @IceLog
    @SaCheckPermission("upms:role:update")
    @Operation(summary = "更新角色接口")
    @PutMapping("/update")
    public R<Boolean> update(@RequestBody @Validated UpdateRoleReqDto reqDto) {
        Boolean result = iSysRoleService.update(reqDto);
        return R.ok(result);
    }

    @IceLog
    @SaCheckPermission("upms:role:delete")
    @Operation(summary = "删除角色接口")
    @DeleteMapping("/delete")
    public R<Boolean> delete(@NotNull(message = "ID不能为空") Long id) {
        Boolean result = iSysRoleService.delete(id);
        return R.ok(result);
    }

}
